/* picsave a file from hires screen 1 */
#include <console.h>
#include <stdio.h>
#include <fcntl.h>
#include <dos33.h>
#include <sgtty.h>
#include <device.h>

/*

When open is used to creat a file under DOS 3.3, param3 is the file's type:

    Param3,hex    File type

    00            Text
    01            Integer basic
    02            Applesoft basic
    04            Binary
    08            Relocatable
    10            S-type file
    20            A-type file
    40            B-type file

*/




extern unsigned HB[];
picsave(savex)
char *savex;
{
     int fh;
     int y,x,c=-1,fa=0x2000,fl=8002;
     char tempchar[2];

	 tempchar[0]=40;
	 tempchar[1]=192;

if((fh=open(savex, O_WRONLY|O_TRUNC|O_CREAT,4)) != -1)
{
    c = write(fh,&fa,2);
	if (c==2)c = write(fh,&fl,2);
	if (c==2)c = write(fh,tempchar,2);

	if (c==2)for(y=0;y<192;y++) {
	 c = write(fh,(char *)(HB[y]),40); /* write each raster */
	 if (c!=40)break;
    }
    if (c==40)c=0;
    else c = -2;
	close(fh);
 }
 return c;

}

